// Shortcuts
var trace = function(message) { YAHOO.log(message, "test"); };
var assert = YAHOO.util.Assert;

flyui.pubmed.Service.TestData = function() {
	this.Rb97D = new flyui.pubmed.Publication();
	this.Rb97D.ncbigene = "http://purl.org/commons/record/ncbi_gene/43231";
	this.Rb97D.pubID = "http://purl.org/commons/article/pmid/11665278";
	this.Rb97D.title = "[New mutants report.]";
	this.Rb97D.date = "1952";
	this.Rb97D.mesh = "60--62";
	this.Rb97D.genes = "26";	
};

/**
 * @class
 * A collection of tests to test the module contents.
 */
flyui.pubmed.Service.ModuleTests = function() {};


/** 
 * Set up function for the flyui.pubmed ModuleTests.
 */
flyui.pubmed.Service.ModuleTests.setUpTest = function() {
	try {
		trace("setUp test");
	} catch (e) {
		flyui.err("setUp error, "+e.name+", "+e.message);
	}
};


/** 
 * Tear down function for the flyui.pubmed ModuleTests.
 */
flyui.pubmed.Service.ModuleTests.tearDownTest = function() {
	try {
		trace("tearDown test");
	} catch (e) {
		flyui.err("tearDown error, "+e.name+", "+e.message);
	}
};


/** 
 * Test that the contents of the flyui.pubmed module have been defined.
 */
flyui.pubmed.Service.ModuleTests.testModuleContents = function() {
	
	flyui.info("Test \"==== flyui.pubmed.Service ModuleTests :: testModuleContents ====\" started.");
	
	assert.isNotUndefined(flyui.pubmed, "flyui.pubmed is undefined");	
	
	assert.isNotUndefined(flyui.pubmed.Service, "flyui.pubmed.Service is undefined");	
	
	assert.isNotUndefined(flyui.pubmed.Publication, "flyui.pubmed.Publication is undefined");	
		
};


/** 
 * Construct a YUI test case for the flyui.pubmed ModuleTests.
 * @return a YUI test case
 * @type YAHOO.tool.TestCase
 */
flyui.pubmed.Service.ModuleTestCase = function() {
	
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.pubmed ModuleTests ===",
		
		setUp : flyui.pubmed.Service.ModuleTests.setUpTest,
		
		tearDown : flyui.pubmed.Service.ModuleTests.tearDownTest,
		
		testModuleContents : flyui.pubmed.Service.ModuleTests.testModuleContents
		
	});
	
	return testCase;
	
};

// ************************************************************
// Publication TESTS
// ************************************************************


/**
 * @class
 * A collection of tests to test the Publication class.
 */
flyui.pubmed.Service.PublicationTests = function() {};


/** 
 * Set up function.
 */
flyui.pubmed.Service.PublicationTests.setUpTest = function() {
	try {
		trace("setUp test");
	} catch (e) {
		flyui.err("setUp error, "+e.name+", "+e.message);
	}
};


/** 
 * Tear down function.
 */
flyui.pubmed.Service.PublicationTests.tearDownTest = function() {
	try {
		trace("tearDown test");
	} catch (e) {
		flyui.err("tearDown error, "+e.name+", "+e.message);
	}
};

flyui.pubmed.Service.PublicationTests.testPublicationClassDefinition = function(){
	flyui.info("Test \"==== flyui.pubmed.Service PublicationTests :: testPublicationClassDefinition ====\" started.");
	
	assert.isNotUndefined(flyui.pubmed.Publication.newInstancesFromSPARQLResults, "newInstancesFromSPARQLResults is undefined");
	
	var publication = new flyui.pubmed.Publication();
	assert.isNotUndefined(publication.pubID, "publication.pubID is undefined");	
	assert.isNotUndefined(publication.date, "publication.date is undefined");
	assert.isNotUndefined(publication.title, "publication.title is undefined");
	assert.isNotUndefined(publication.mesh, "publication.mesh is undefined");
	assert.isNotUndefined(publication.genes, "publication.genes is undefined");
	
};

//flyui.pubmed.Service.TestData.comparePublications = function( expected, actual ) {
//
//	trace("test pubID");	
//	assert.areEqual(expected.pubID, actual.pubID, "pubID not as expected");
//	
//	trace("test date");	
//	assert.areEqual(expected.date, actual.date, "date not as expected");
//	
//	trace("test title");	
//	assert.areEqual(expected.title, actual.title, "title not as expected");
//	
//	trace("test genes");	
//	flyui.util.arrayMembersAreEqual(expected.genes, actual.genes, "title not as expected");
//	
//	trace("test mesh");	
//	flyui.util.arrayMembersAreEqual(expected.mesh, actual.mesh, "mesh not as expected");
//	
//}


flyui.pubmed.Service.PublicationTests.testNewPublicationsFromSPARQLResults = function(){
	flyui.info("Test \"==== flyui.pubmed.Service PublicationTests :: testNewPublicationsFromSPARQLResults ====\" started.");

	var testData = new flyui.pubmed.Service.TestData();
	
//	var publications = flyui.pubmed.Publication.newInstancesFromSPARQLResults(testData.resultSet_Rb97D);
	
//	assert.areEqual(24, publications.length, "24 publication expected");
	
	// ordered by the year
//	flyui.pubmed.Service.TestData.comparePublications(testData.FBgn0002828_2, publications[0]);
//	
//	flyui.pubmed.Service.TestData.comparePublications(testData.FBgn0002828_1, publications[1]);	
};

/** 
 * Construct a YUI test case for the flyui.pubmed Tests.
 * @return a YUI test case
 * @type YAHOO.tool.TestCase
 */
flyui.pubmed.Service.PublicationTestCase = function() {
	
	var testCase = new YAHOO.tool.TestCase({
		
		name: "=== flyui.pubmed.Service PublicationTests ===",
		
		setUp : flyui.pubmed.Service.PublicationTests.setUpTest,
		
		tearDown : flyui.pubmed.Service.PublicationTests.tearDownTest,
		
		testPublicationClassDefinition : flyui.pubmed.Service.PublicationTests.testPublicationClassDefinition,
				
//		testNewPublicationsFromSPARQLResults : flyui.pubmed.Service.PublicationTests.testNewPublicationsFromSPARQLResults
				
	});
	
	return testCase;
	
};


// ************************************************************
// TEST SUITE & RUNNER
// ************************************************************


/** 
 * Construct a YUI test suite for the flyui.pubmed module.
 * @param {String} endpointURL URL of service
 * @return a YUI test suite
 * @type YAHOO.tool.TestSuite
 */
flyui.pubmed.Service.TestSuite = function(endpointURL) {
	var suite = new YAHOO.tool.TestSuite("== flyui.pubmed.Service Test Suite ==");
	
	suite.add(flyui.pubmed.Service.ModuleTestCase());
	suite.add(flyui.pubmed.Service.PublicationTestCase());
//	suite.add(flyui.pubmed.Service.ServiceTestCase(endpointURL));
	return suite;
}

/** 
 * Run the flyui.pubmed test suite.
 * @param {String} endpointURL URL of service
 */
flyui.pubmed.Service.runTests = function(endpointURL) {
	trace("flyui.pubmed.Service :: running tests");
	YAHOO.tool.TestRunner.add(flyui.pubmed.Service.TestSuite(endpointURL));
	YAHOO.tool.TestRunner.run();
}
